package cn.virens.library.widget.adapter;

import android.view.View;

import org.xutils.common.util.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * (c) Copyright 2016 by
 *
 * @author :yyzh
 * @description : 通用RecyclerView数据源适配器
 * @package :cn.loioi.test
 * @创建时间 :2016/3/25 21:10
 */
public abstract class SimpleAdapter<T> extends AbstractAdapter<T> {
    /**
     * 数据集
     */
    protected final List<T> mDataSet = new ArrayList<>();
    /**
     * 单击事件
     */
    private OnItemClickListener mOnItemClickListener;

    public SimpleAdapter(int layoutID) {
        super(layoutID);
    }

    public SimpleAdapter(int layoutID, List<T> list) {
        super(layoutID, list);
    }

    /**
     * 获取 - 点击事件
     *
     * @return
     */
    protected OnItemClickListener getOnItemClickListener() {
        return this.mOnItemClickListener;
    }

    /**
     * 设置点击事件
     *
     * @param listener
     */
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    /**
     * 配置 视图持有者
     *
     * @param holder RecyclerViewHolder
     */
    protected void configRecyclerViewHolder(final RecyclerViewHolder holder) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.d("on item click " + holder.position);
                if (getOnItemClickListener() != null) {
                    getOnItemClickListener().onItemClick(holder.position);
                }
            }
        });
    }

    /**
     * 点击事件Listener
     */
    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}